import { create } from 'zustand'
import { immer } from "zustand/middleware/immer"
interface UserStore {
  userName: string
  num: number
}
export const useUserStore = create<UserStore>()(
  immer(
    () => ({
      userName: 'LiuJie1998',
      num: 0
    })
  )
)

export const changeName = () => {
  useUserStore.setState((state) => { state.userName = 'laoer536' })
}
export const changeNum = () => {
  useUserStore.setState((state) => { state.num += 1 })
}

export const changeNumAsync = async () => {
  const rate = await Promise.resolve(2)
  useUserStore.setState((state) => { state.num *= rate })
}
